@echo off
setlocal enabledelayedexpansion
set CUR_PATH=%~dp0
cd %CUR_PATH%
set DIR=LastRes
set backup_dir=BackUpRes
set DIR2=HotUpdateRes
set DIR3=client_publish
set h=%time:~0,2%
set h=%h: =0%
set DIR_TIME=%DIR3%\%date:~0,4%-%date:~5,2%-%date:~8,2%-%h%%time:~3,2%

@REM set DIR3=HotUpdateRes
set FILE_NAME=change.txt
@REM set local enabledelayedexpansio
REM start "" "F:\Program Files\Git\git-bash.exe" -c "cd ../HotUpdateRes && ls;bash"


@REM start /wait "" "F:\Program Files\Git\git-bash.exe" -c "cd ../HotUpdateRes && git archive -o ../HotUpdateRes-Work/update.zip HEAD $(git diff --name-only HEAD)"
@REM 添加未管理文件
call "F:\Program Files\Git\git-bash.exe" -c "cd ./%DIR2% && git add ."
@REM 导出所有差异
call "F:\Program Files\Git\git-bash.exe" -c "cd ./%DIR2% &&  git diff --name-only HEAD  > ../%FILE_NAME%"

RD /S /Q %DIR%
if not exist %DIR% (
    md %DIR%
)

RD /S /Q %backup_dir%
if not exist %backup_dir% (
    md %backup_dir%
)

set suffx=3
set js_url=oss://rmex-jsmj-new/Download/ClientRes/1003_%suffx%
set lyg_url=oss://rmex-lygmj-new/Download/ClientRes/1001_%suffx%
set sb_url=oss://rmex-lygmj-new/Download/ClientRes/1006_%suffx%
for /f %%a in (%FILE_NAME%) do (
    set aaa=%%%a
    set source2=.\%DIR2%\!aaa!

    @REM echo %DIR2% : %%%a
    set des2= %%~dpa
    echo des2 : !des2!
    set source=!source2:/=\!
    set des1=!des2:/=\!
    set des=!des1:%CUR_PATH%=%CUR_PATH%%DIR%\!
    set buckup=!des1:%CUR_PATH%=%CUR_PATH%%backup_dir%\!
    
    echo source !source!
    echo des !des!
    @REM 
    if not exist !des! (
        md !des!
    )
    copy !source! !des!


    @REM 下载备份start---------------------------------
    echo aaa: !aaa!
    set ossfile=!aaa:JiangSu=%js_url%!
    
    if !ossfile! == !aaa! (
        set ossfile=!aaa:LianYunGang=%lyg_url%!
        
        if !ossfile! == !aaa! (
            set ossfile=!aaa:SuBei=%sb_url%!
            if not !ossfile! == !aaa! set isdown=1

        ) else ( set isdown=1)
        
    ) else ( set isdown=1)

    if defined isdown (
        if not exist !buckup! md !buckup!
        echo ossfile : !ossfile!   buckup : !buckup!
        .\ossutil64 -c ./config12 cp -f !ossfile! !buckup!
    )

    @REM @REM 下载备份end---------------------------------

    set destime=!des:%DIR%=%DIR_TIME%!
    @REM echo destime !destime!
    if not exist !destime! (
        md !destime!
    )
    copy !source! !destime!


)
@REM echo destime1 !destime!
@REM echo destime2 %destime%
@REM echo FILE_NAME %FILE_NAME%
copy %FILE_NAME% %DIR%
copy %FILE_NAME% %DIR_TIME%

